#ifdef GL_ES
precision mediump float;
#endif

uniform float u_time;
uniform vec2 u_resolution;
uniform vec2 u_mouse;

struct Rect{
    vec2 size;
    vec2 origin;
    vec3 color;
}rect;

bool rect_contains(in Rect rect,vec2 point){
    float left=rect.origin.x-rect.size.x/2.;
    float bottom=rect.origin.y-rect.size.y/2.;
    float right=rect.origin.x+rect.size.x/2.;
    float top=rect.origin.y+rect.size.y/2.;
    return point.x>=left&&point.x<=right&&point.y>=bottom&&point.y<=top;
}

const float PI = 3.14159;
mat2 rotate2d(float degress){
    float rad = degress * PI / 180.;
    float s = sin(rad);
    float c = cos(rad);
    return mat2(vec2(c,s),vec2(-s,c));
}
mat2 scale2d(float sx,float sy){
    return mat2(vec2(sx,0.),vec2(0.,sy));
}

vec3 cyan=vec3(.0,1.,1.);

void main(){
    vec2 st=gl_FragCoord.xy/u_resolution;
    
    vec3 color=vec3(.0);
    
    mat3 tMat=mat3(
        vec3(1.,0.,.0),
        vec3(0.,1.,.0),
        vec3(0.,0.,1.)
    );
    
    mat3 rMat=mat3(
        vec3(1.,0.,.0),
        vec3(0.,1.,.0),
        vec3(0.,0.,1.)
    );
    
    mat3 sMat=mat3(
        vec3(1.,0.,.0),
        vec3(0.,1.,.0),
        vec3(0.,0.,1.)
    );
    
    
    mat3 worldMat=tMat*rMat*sMat;
    
    // mat2 r = rotate2d(45.0 * sin(u_time));
    mat2 r = rotate2d(30.0);
    mat2 s = scale2d(1.5,2.);
    // st = r * s * st;
    st = s * r * st;

    // rect
    rect.origin= vec2(.5,.5);
    // (worldMat*vec3(vec2(.5,.5),1.)).xy;
    rect.size=vec2(.1,.1);
    rect.color=cyan;
    
    if(rect_contains(rect,st)){
        color+=rect.color;
    }
    
    gl_FragColor=vec4(color,1.);
}